package com.nowcoder.community.service;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author szq
 * @create 2023-01-18 15:06
 * @description
 */
@Component
public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if ("alphaService".equals(beanName)) {
            System.out.println("第四步：bean后处理器的Before方法");
        }
        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if ("alphaService".equals(beanName)) {
            System.out.println("第七步：bean后处理器的After方法");
        }
        return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
    }
}
